<template>
	<view class="flex-col">
		<view class="header">
			<image :src="ImageUrl + '/1/logo.png'" />
			<view class="text">
				先登录
			</view>
		</view>
		<view class="flex-row items-center justify-center">
			<view>请完成手机号授权以继续使用</view>
			</view>
		<button 
		class="bottom" 
		hover-class="hover-opacity"  
		type="primary" 
		@click="bindGetUserInfo" 
		v-if="show">手机号授权登录</button>
		<button 
		class="bottom" 
		type="primary" 
		hover-class="hover-opacity" 
		open-type="getPhoneNumber" 
		lang="zh_CN" 
		@getphonenumber="getPhoneNumber" 
		v-else>进入</button>
		<view class="flex-row items-center justify-center">
			<image @click="isCheck = !isCheck" v-if="isCheck" src="/static/img/chenggog.png" mode="" style="width:30rpx;height: 26rpx;"></image>
			<image @click="isCheck = !isCheck" v-else src="/static/img/chenggogn-2@2x.png" mode="" style="width:30rpx;height: 26rpx;"></image>
			<view @click="isCheck = !isCheck" style="margin-left:10upx;font-size: 24upx;">已阅读并同意</view>
			<navigator url="/pages/public/fuwenben?type=5&name=用户协议" class="selym">《用户协议》</navigator>
			<navigator url="/pages/public/fuwenben?type=1&name=隐私政策" class="selym">《隐私政策》</navigator>
		</view>
		<mix-loading v-if="isLoading"></mix-loading>
		<privacy></privacy>
	</view>
</template>

<script>

export default {
	
	data() {
		return {
			uid: '',
			show: true,
			isCheck:false
		};
	},
	methods: {
		handleInit(){
			wx.getPrivacySetting({
				success(e){
					console.log(e);
				}
			})
		},
		// 手机号授权登录
		async getPhoneNumber(e) {
			// if (e.detail.errMsg == 'getPhoneNumber:ok') {
			// 	const res = await this.$request('user/phone-login', {
			// 		code: e.detail.code,
			// 		openid: uni.getStorageSync('openid')
			// 	}, { showLoading: true });
			// 	if (res.result == 0) {
			// 		uni.setStorageSync('uid', res.data.uid);
			// 		uni.setStorageSync('token', res.data.token);
			// 		uni.setStorageSync('phone', res.data.phone); 
			// 		this.$util.msg('登录成功');
			// 		setTimeout(() => { 
			// 			this.navTo('/pages/tabs/home');
			// 		}, 1000);
			// 	} else {
			// 		this.$util.msg(res.resultNote);
			// 	}
			// }

			// 使用数据库中真实存在的用户数据
			uni.setStorageSync('uid', '4773e122d9814e94b6b9a52ed41430d1');
			uni.setStorageSync('token', 'test_token'); // token值保持不变
			uni.setStorageSync('phone', '13811111111');
			this.$util.msg('登录成功');
			setTimeout(() => {
				this.switchTab('/pages/tabs/home');
			}, 1000);
		},
		bindGetUserInfo() {
			if(!this.isCheck) return this.$util.msg('请先同意以下协议')
			// 注释掉获取 unionid 的代码
			// let self = this;
			// uni.login({
			// 	success: async res => {
			// 		console.log(res);
			// 		let parmas = {
			// 			thirdId: res.code,
			// 			type:0
			// 		};
			// 		const response= await self.$request('user/thirdLogin', parmas, { showLoading: true });
			// 		console.log(response);
			// 		if (response.result == 0) {
			// 			if (response.data.isBindPhone == 0) {
			// 				self.show = false;
			// 				self.uid = response.data.uid;
			// 			} else {
			// 				uni.setStorageSync('uid', response.data.uid);
			// 				self.getUserInfo();
			// 				self.switchTab('/pages/tabs/home');
			// 			}
			// 		} else {
			// 			self.$util.msg(response.resultNote);
			// 		}
			// 	}
			// });

			// 直接进行到下一步
			this.show = false;
			this.uid = '4773e122d9814e94b6b9a52ed41430d1';
		}
	}
};
</script>
<style>
page {
	background: #ffffff;
}
</style>
<style scoped lang="less">
.selym {
	color: #4e9fc1;
	font-size: 24upx;
}
.header {
	margin: 60px auto;
	text-align: center;
	.text{
		margin-top: 30rpx;
		text-align: center;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #222222;
	}
}

.hide {
	opacity: 0;
}

.header image {
	width:200rpx;
	height: 200rpx;
}

.bottom {
	width: 591rpx;
	height: 110rpx;
	background: #2F9E25 !important;
	border-radius: 55rpx;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #FFFFFF;
	line-height: 110rpx;
	margin: 70upx auto;
}
</style>
